package edu.ucsd.cse110;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Displays five navigation buttons: Log, WOD, Stats, Lifts, and Settings.
 */
public class HomeFragment extends Fragment implements OnClickListener {
	/**
	 * TODO: Need documentation.
	 */
	public void onClick(View v) {
		switch (v.getId()) {
		// Left arrow.
		case R.id.left_arrow:
			XFitTracker.mPager.setCurrentItem(0);
			break;
		// Right arrow.
		case R.id.right_arrow:
			XFitTracker.mPager.setCurrentItem(2);
			break;
		// Opens the settings screen.
		case R.id.settings_button:
			super.startActivity(new Intent(getActivity(),
					SettingsActivity.class));
			break;
		// Scrolls the page to the right.
		case R.id.wodList_button:
			((ViewPager) getActivity().findViewById(R.id.main_viewpager))
					.setCurrentItem(2);
			break;
		// Scrolls the page to the left.
		case R.id.logbook_button:
			((ViewPager) getActivity().findViewById(R.id.main_viewpager))
					.setCurrentItem(0);
			break;
		// Opens the lifts screen.
		case R.id.lifts_button:
			super.startActivity(new Intent(getActivity(), LiftActivity.class));
			break;
		// Opens the stats screen
		case R.id.stats_button:
			super.startActivity(new Intent(getActivity(), StatsActivity.class));
			break;
		}
	}

	/**
	 * TODO: Need documentation.
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (container == null) {
			return null;
		}

		setHasOptionsMenu(true);

		View view = inflater.inflate(R.layout.home, container, false);

		View btnSettings = view.findViewById(R.id.settings_button);
		btnSettings.setOnClickListener(this);

		View btnBenchmark = view.findViewById(R.id.wodList_button);
		btnBenchmark.setOnClickListener(this);

		View btnLogbook = view.findViewById(R.id.logbook_button);
		btnLogbook.setOnClickListener(this);

		View btnLifts = view.findViewById(R.id.lifts_button);
		btnLifts.setOnClickListener(this);

		View btnStats = view.findViewById(R.id.stats_button);
		btnStats.setOnClickListener(this);

		ImageView imgLeftArrow = (ImageView) view.findViewById(R.id.left_arrow);
		imgLeftArrow.setOnClickListener(this);

		ImageView imgRightArrow = (ImageView) view
				.findViewById(R.id.right_arrow);
		imgRightArrow.setOnClickListener(this);

		return view;
	}
}